package com.xrkol.sharelib.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.xrkol.sharelib.dao.ResponseStatusLogDao;
import com.xrkol.sharelib.entity.ClientType;
import com.xrkol.sharelib.entity.ResponseLogType;
import com.xrkol.sharelib.entity.ResponseStatusLog;

/**
 * @author dipei.ruan
 *
 */
@Repository
public class ResponseStatusLogDaoImpl extends
		BaseDaoImpl<ResponseStatusLog, String> implements ResponseStatusLogDao {

	private static String LIST_BY_SUCCESS = "from ResponseStatusLog r where r.logType=? and r.clientType=? and r.timestamp>=? and r.timestamp<=? ";

	private static String LIST_BY_TIMESTAMP = "from ResponseStatusLog r where r.clientType=? and r.timestamp>=? and r.timestamp<=? ";

	private static String ORDER_BY_TIMESTAMP = "order by timestamp ";

	private static String DESC = "desc ";

	@Override
	public List<ResponseStatusLog> getListByTimestamp(Long startTime,
			Long endTime, ClientType clientType, boolean timeASC, Integer page) {
		return executeQueryWithPagination(LIST_BY_TIMESTAMP, ORDER_BY_TIMESTAMP
				+ (timeASC ? "" : DESC), page, clientType, startTime, endTime);
	}

	@Override
	public List<ResponseStatusLog> getListByTimestamp(Long startTime,
			Long endTime, ResponseLogType logType, ClientType clientType,
			boolean timeASC, Integer page) {
		return executeQueryWithPagination(LIST_BY_SUCCESS, ORDER_BY_TIMESTAMP
				+ (timeASC ? "" : DESC), page, logType, clientType, startTime,
				endTime);
	}

}
